﻿using System;
using System.Linq;
using Contracts.Entities;

namespace Model.Movie
{
    public class ReadMovieItem
    {
        private MovieDatabaseEntities entities;

        public ReadMovieItem()
        {
            this.entities = new MovieDatabaseEntities();
        }

        public void Process(int id)
        {
            var query = entities.Movies.SingleOrDefault(m => m.Id == id);
            var movieItem = MovieItemConverter.GetItem(query);

            OnCompleted(movieItem);
        }

        public event Action<MovieItem> OnCompleted = delegate { };
    }
}
